/**
 * Created by CN-xin on 2018/10/22.333333333
 */
var  modelActi  = localStorage.getItem('sqlData');
console.log(modelActi);
mini.parse();
var grid = mini.get("datagrid1");
var url = bootPATH + "../frame/frame1/pages/activiti/";      //路径前缀

mini_debugger = false;
$(listDetai);

/*加载数据*/
function listDetai(){
    var rowString = localStorage.getItem("sqlData");
    console.log("rowString",rowString);
    row = JSON.parse(rowString);
    console.log("row",row)
    $.ajax({
        // url: "http://localhost:8080/DSMP/formltems/findByModelId.do?modelId=330",
        url: ajaxUrl + "/model/findByProcessId.do?modelId=" + row.id,
        type: "post",
        dataType: "json",
        contentType : "application/json",
        success: function (data) {
            console.log("data",data);
            if (data.state == 'success'){
                var activitiList = data.data;
                console.log(activitiList);
                grid.setData(activitiList);
            }else {
                mini.alert(data.message);
            }

        },
        error: function (data) {
        }
    });
}

/*查看流程图*/
function sercherPng() {
    var row = grid.getSelected();
    console.log(row)
    var deploymentId=row.deploymentId
    console.log(row.deploymentId)
    var diagramResourceName=row.diagramResourceName
    console.log(row.diagramResourceName)
    fileUrl = ajaxUrl+"/process/showView.do?deploymentId="+deploymentId+"&diagramResourceName="+diagramResourceName;
    images = document.getElementById("imgs")
    images.src = fileUrl;
    var process = document.getElementById("process");
    console.log(process);
    process.style.display = "block";
}

/*关闭*/
function close(){
    images = document.getElementById("imgs")
    images.src = '';
    var process = document.getElementById("process");
    console.log(process);
    process.style.display = "none";
}

/*跳转新增页面*/
function Toadd(){
    var table = document.getElementById("add")
    table.style.display = "block";
}

/*创建*/
function add(){
    var rowString = localStorage.getItem("sqlData");
    console.log("rowString",rowString);
    var row1 = JSON.parse(rowString);
    console.log("row1",row1)
    var process = mini.get("processName");
    console.log(process);
    var processName = process.getValue();
    $.ajax({
        url:ajaxUrl + "/process/create.do",
        type:"POST",
        data:{
            processName:processName,
            modelId:row1.id
        },
        success:function(data){
            var process = document.getElementById("processName")
            process.value = "";
            console.log(data)
            console.log(data.modelId)
            var id = data.modelId;
            window.location.href = ajaxUrl + "/modeler.html?modelId="+id;
            console.log("成功");
        },
        error:function(data){
            console.log("失败");
        }
    })
    var table = document.getElementById("add")
    table.style.display = "none";
}

/*取消*/
function out(){
    var table = document.getElementById("add")
    table.style.display = "none";
}

/*删除模型*/
function remove(){
    var row = grid.getSelected();
    if(row==null){
        mini.alert("请选择要删除的模型！！！")
    }else{
    var id=row.id
    if(confirm("是否删除")){
        $.ajax({
            url:ajaxUrl+"/process/remove.do?modelId="+id,
            type:"POST",
            success:function(data){
                 listDetai();
            },
            error:function(data){
                 listDetai();
            }
        })
    }
    }
}

/*编辑*/
function ToModel() {
    console.log("编辑流程")
    var row = grid.getSelected();
    if (row == null) {
        mini.alert("请选择要编辑的模型！！！")
    } else {
        var id = row.id
        console.log(row)
        console.log(id)
        window.location.href = ajaxUrl + "/modeler.html?modelId="+id;
    }
}

/*部署*/
// *部署*function deploy(){
//     var row = grid.getSelected();
//     if (row == null) {
//         mini.alert("请选择要部署的模型！！！")
//     } else {
//         var modelId = row.id
//         console.log("modelId")
//         $.ajax({
//             url:ajaxUrl + "/process/deploy.do?modelId="+modelId,
//             type:"POST",
//             success:function(data){
//                 mini.alert("部署成功")
//                 listDetai();
//             },
//             error:function(data){
//                 mini.alert("部署失败")
//                 listDetai();
//             }
//
//         })
//
//     }listDetai
// }